home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / howtos1r / systray.bas < prev    next >
BASIC Source File  |  1997-01-16  |  4KB  |  94 lines

  1. Attribute VB_Name = "mSysTray"
  2. Option Explicit
  3.  
  4. '-------------------------------------------------------
  5. ' Api Declares....
  6. '-------------------------------------------------------
  7. Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal MSG As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  8. Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  9. Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  10. Public Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
  11. Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal ByteLen As Long)
  12. Public Declare Function DrawEdge Lib "user32" (ByVal hDC As Long, qrc As RECT, ByVal edge As Long, ByVal grfFlags As Long) As Boolean
  13.  
  14. '-------------------------------------------------------
  15. ' Api Constants...
  16. '-------------------------------------------------------
  17. Public Const GWL_USERDATA = (-21&)
  18. Public Const GWL_WNDPROC = (-4&)
  19. Public Const WM_USER = &H400&
  20.  
  21. Public Const TRAY_CALLBACK = (WM_USER + 101&)
  22. Public Const NIM_ADD = &H0&
  23. Public Const NIM_MODIFY = &H1&
  24. Public Const NIM_DELETE = &H2&
  25. Public Const NIF_MESSAGE = &H1&
  26. Public Const NIF_ICON = &H2&
  27. Public Const NIF_TIP = &H4&
  28.  
  29. Public Const WM_MOUSEMOVE = &H200&
  30. Public Const WM_LBUTTONDOWN = &H201&
  31. Public Const WM_LBUTTONUP = &H202&
  32. Public Const WM_LBUTTONDBLCLK = &H203&
  33. Public Const WM_RBUTTONDOWN = &H204&
  34. Public Const WM_RBUTTONUP = &H205&
  35. Public Const WM_RBUTTONDBLCLK = &H206&
  36.  
  37. 'DrawEdge constants
  38. Public Const BDR_RAISEDOUTER = &H1&
  39. Public Const BDR_RAISEDINNER = &H4&
  40. Public Const BF_LEFT = &H1&             ' Border flags
  41. Public Const BF_TOP = &H2&
  42. Public Const BF_RIGHT = &H4&
  43. Public Const BF_BOTTOM = &H8&
  44. Public Const BF_RECT = BF_LEFT Or BF_TOP Or BF_RIGHT Or BF_BOTTOM
  45. Public Const BF_SOFT = &H1000&          ' For softer buttons
  46.  
  47. '-------------------------------------------------------
  48. ' Api Types....
  49. '-------------------------------------------------------
  50. Public Type NOTIFYICONDATA
  51.     cbSize As Long
  52.     hwnd As Long
  53.     uID As Long
  54.     uFlags As Long
  55.     uCallbackMessage As Long
  56.     hIcon As Long
  57.     szTip As String * 64
  58. End Type
  59. Public Type RECT
  60.     Left As Long
  61.     Top As Long
  62.     Right As Long
  63.     Bottom As Long
  64. End Type
  65.  
  66. Public PrevWndProc As Long
  67.  
  68. '------------------------------------------------------------
  69. Public Function SubWndProc(ByVal hwnd As Long, ByVal MSG As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  70. '------------------------------------------------------------
  71. ' This is the control subclassed window proc.
  72. '------------------------------------------------------------
  73.     Dim SysTray As cSysTray                         ' SysTray class variable
  74.     Dim ClassAddr As Long                           ' long pointer to class object
  75. '------------------------------------------------------------
  76.     Select Case MSG                                 ' Determine
  77.     Case TRAY_CALLBACK                              ' Callback message received when user clicks on system tray...
  78.         ' Retrieve long pointer to class object, this was saved in the _
  79.           USERDATA of the window struct. after the user control was subclassed...
  80.         ClassAddr = GetWindowLong(hwnd, GWL_USERDATA) ' get pointer to object
  81.         CopyMemory SysTray, ClassAddr, 4            ' Copy an unreferenced pointer to object into variable
  82.         
  83.         SysTray.SendEvent lParam, wParam            ' Send windows message\user event to control
  84.         
  85.         CopyMemory SysTray, 0&, 4                   ' Nullify object pointer
  86.     End Select
  87.    
  88.     ' Forward all messages to previous window procedure...(This must be done)
  89.     SubWndProc = CallWindowProc(PrevWndProc, hwnd, MSG, wParam, lParam)
  90. '------------------------------------------------------------
  91. End Function
  92. '------------------------------------------------------------
  93.  
  94.